<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/8/31 0031
  Time: 14:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
  <base href="<%=basePath%>">
  <meta charset="utf-8"/>
  <title></title>
  <link rel="stylesheet" type="text/css" href="easyui-1.3.6/themes/default/easyui.css">
  <link rel="stylesheet" type="text/css" href="easyui-1.3.6/themes/icon.css">
  <link rel="stylesheet" type="text/css" href="easyui-1.3.6/demo/demo.css">
  <script type="text/javascript" src="easyui-1.3.6/jquery.min.js"></script>
  <script type="text/javascript" src="easyui-1.3.6/jquery.easyui.min.js"></script>

</head>
<div class="row">
  <div class="col-md-12">
    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
    <h3 class="page-title" id="index-page-title" style="font: normal 30px/0.8em '微软雅黑'">孜点教科</h3>
    <ul class="page-breadcrumb breadcrumb">
     <%-- <li>
        <i class="fa fa-home"></i>
        首页
        <i class="fa fa-angle-right"></i>
      </li>--%>
      <li>
        老师管理
        <i class="fa fa-angle-right"></i>
      </li>
      <li>
        <%--<a href="javascript:;">--%>
        管理老师教学组
        <%--</a>--%>
      </li>
    </ul>
    <!-- END PAGE TITLE & BREADCRUMB-->
  </div>
</div>

<input class="easyui-searchbox" data-options="prompt:'请输入教师编号或教师名字或教师职务职务或教师身份证查询',searcher:doSearch" style="width:450px;height: 48px;background: transparent;border:none;">

<div style="margin:20px 0;"></div>
<div id="test" class="easyui-dialog" data-options="closed:true,modal:true,title:'是否要删除当前所选择老师的教学组'" style="width: 400px;">
  <div style="width:368px;height:160px;margin:auto;" >
      <a href="javascript:void(0)" class="easyui-linkbutton" onclick="delTeacher()" style="display:inline-block;width:195px;height:30px;margin:65px 0px 0px 86px;line-height:30px;">确认删除当前所选择老师的教学组</a>
  </div>
</div>
<table id="dg" title="老师信息表" style="width:auto;height:auto" data-options="
				rownumbers:true,
				singleSelect:true,
				autoRowHeight:false,
				pagination:true,
				pageSize:10
				">
  <thead>
  <tr>
    <th field="teacherId" width="100">教师编号</th>
    <th field="teacherName" width="100">教师名字</th>
    <th field="teacherSex" width="50">教师性别</th>
    <th field="teacherIdCard" width="200">教师身份证</th>
    <th field="teacherPhoneNumber" width="100">教师电话号码</th>
    <th field="teacherPosition" width="100">教师职称</th>
    <th field="teacherSchool" width="200">教师学校</th>
    <th field="teacherCollege" width="200">教师学院</th>
    <th field="teacherGroup" width="200">教师分组</th>
  </tr>
  </thead>
</table>
<div id="test1" class="easyui-dialog" data-options="closed:true,modal:true,title:'添加教师的教学组信息'" style="width:400px;height:580px;">
  <form id="ff" class="easyui-form" method="post" data-options="novalidate:true">
    <input type="hidden" name="teacherId" id="teacherId">
    <input type="hidden" name="teaGroupId" id="teachingGroupId">
    <input type="hidden" value="${user.teacherid}" name="manageId">
    <table id="dg1" title="教学组信息表选择一个组进行分配" style="width:auto;height:auto" data-options="
				rownumbers:true,
				singleSelect:true,
				autoRowHeight:false,
				pagination:true,
				pageSize:10
				">
      <thead>
      <tr>
        <th field="teachingGroupId" width="100">教学组编号</th>
        <th field="teachingGroupMame" width="100">教学组名</th>
        <th field="teachingGroupManageId" width="100">管理id</th>
      </tr>
      </thead>
    </table>
    <div style=";width:257px;height:35px;margin:0 auto;margin-top:30px;">
        <tr>
      <td >教师职责:</td>
      <td ><select class="easyui-combobox" name="teachingGroupPosition" style="width:180px;height:30px; border:1px solid #d6dde5;background-color:transparent;padding:0px 10px;">
        <option value="管理">管理</option>
        <option value="教学">教学</option>
      </select></td>
    </tr>
    </div>
  </form>
  <div style="text-align:center;padding:5px">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:140px;height:30px;margin-bottom: 20px;">确定</a>
  </div>
</div>

<div id="test2" class="easyui-dialog" data-options="closed:true,modal:true,title:'添加教学组信息'" style="width:400px">
  <form id="ff2" class="easyui-form" method="post" data-options="novalidate:true"  style="display:block;width:257px;height:45px;margin:0px auto;margin-top: 20px;">
    <input type="hidden" value="${user.teacherid}" name="manageId">
    <tr>
      <td>教学组名:</td>
      <td><input class="easyui-validatebox textbox" name="teachingGroupName"
                 data-options="required:true,missingMessage:'不能为空！',validType:'length[1,10]',invalidMessage:'长度请为1到10之间！'" style="width:200px;height:30px; border:1px solid #d6dde5;background-color:transparent;padding:0px 10px;margin: 5px 0px;"></td>
    </tr>
  </form>
  <div style="text-align:center;padding:5px">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm1()" style="width:116px;height:30px;margin-bottom: 20px;">提交</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:116px;height:30px;margin-bottom: 20px;">清除</a>
  </div>
</div>
<script>
  var i = 1;
  function pagerFilter(data){
    if(i==1&&data[0]!=null){
      var to = data[0].total;
      var wh = data[0].wh;
    }else if(i==2&&data!=null){
      var to = data.total;
      var wh = data.wh;
    }else{
      var to = 0;
      var wh = "";
    }
    if (typeof to== 'number' && typeof data.splice == 'function'){	// is array
      data = {
        total:to,
        rows: data,
        wh:wh
      }
      i=2;
    }
    var dg = $(this);
    var opts = dg.datagrid('options');
    var pager = dg.datagrid('getPager');
    pager.pagination({
      onSelectPage:function(pageNum, pageSize){
        opts.pageNumber = pageNum;
        opts.pageSize = pageSize;
        pager.pagination('refresh',{
          pageNumber:pageNum,
          pageSize:pageSize
        });
        var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
//    var end = start + parseInt(opts.pageSize);
        data.rows = (getData(start,parseInt(opts.pageSize),wh));
        dg.datagrid('loadData',data);
      }
    });
    return data;
  }

  $(function(){
    $('#dg').datagrid({
      toolbar:[
        {
          text:'删除所选中的一条信息',
          iconCls:'icon-remove',
          handler:function(){
            $('#test').window('open');
          }
        },
        {
          text:'给当前老师分配一个教师组',
          iconCls:'icon-search',
          handler:function(){
            i=1;
            $('#test1').window('open');
            $('#dg1').datagrid({loadFilter:pagerFilter1}).datagrid('loadData', getData1(0,10,""));
            var row = $('#dg').datagrid('getSelected');
            $("#teacherId").val(row.teacherId);
          }
        },
        {
          text:'添加一个教师组',
          iconCls:'icon-search',
          handler:function(){
            $('#test2').window('open');
          }
        }
      ]
    })
    $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData(0,10,""));
  });


  function delTeacher(){
    var row = $('#dg').datagrid('getSelected');
    if (delData(row.teacherId)==200){
      var index = $('#dg').datagrid('getRowIndex', row);
      $('#test').window('close');
      $('#dg').datagrid('deleteRow', index);
    }else{
      alert("删除失败")
    }
  }

  function delData(s){
    var code1 = 0;
    $.ajax({
      method : 'post',
      url : 'rest/page/manageTeachingGroup/del',
      data: 'manageId=${user.teacherid }&teacherId='+s+'',
      async : false,
      dataType : 'json',
      success : function(code) {
        code1 = code.code
        if(code.code == 200){
          $.messager.show({title:'操作提示',msg:code.message+"请点击表单下刷新按钮刷新显示",showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }else{
          $.messager.show({title:'操作提示',msg:code.message,showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }
      },
      error : function() {
        alert('error');
      }
    });
    return code1
  }

  function getData(r,p,s){
    var infor_data = [];
    var total = 0;
    $.ajax({
      method : 'post',
      url : 'rest/page/manageTeachingGroup/sel',
      data:'startrow='+r+'&pageSize='+p+'&teacherId='+s+'&manageId=${user.teacherid}',
      async : false,
      dataType : 'json',
      success : function(data) {
        infor_data = data.data
        total = data.total
      },
      error : function() {
        alert('error');
      }

    });
    var rows = [];
    if(infor_data!=null) {
      for (var i1 = 0; i1 < infor_data.length; i1++) {
        rows.push({
          total: total,
          wh: s,
          teacherId: infor_data[i1].teacherId,
          teacherCollege: infor_data[i1].teacherCollege,
          teacherIdCard: infor_data[i1].teacherIdCard,
          teacherName: infor_data[i1].teacherName,
          teacherPhoneNumber: infor_data[i1].teacherPhoneNumber,
          teacherPosition: infor_data[i1].teacherPosition,
          teacherSchool: infor_data[i1].teacherSchool,
          teacherSex: infor_data[i1].teacherSex,
          teacherGroup:infor_data[i1].teacherGroup
        });
      }
    }
    return rows;
  }

  function doSearch(value){
    i = 1;
    $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData(0,10,value));
  }

  function submitForm() {
    var row = $('#dg1').datagrid('getSelected');
    $("#teachingGroupId").val(row.teachingGroupId);
    $('#ff').form('submit', {
      url : 'rest/page/manageTeachingGroup/addTea',
      onSubmit: function () {
        return $(this).form('enableValidation').form('validate');
      },
      success : function(data){
        var obj = JSON.parse(data)
        if(obj.code == 200){
          $.messager.show({title:'操作提示',msg:obj.message+"请刷新显示",showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
          $('#test1').window('close');
        }else{
          $.messager.show({title:'操作提示',msg:obj.message,showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }
      }
    });
  }

  function getData1(r,p,s){
    var infor_data1 = [];
    var total1 = 0;
    $.ajax({
      method : 'post',
      url : 'rest/page/manageTeaGroup/select',
      data:'startrow='+r+'&pageSize='+p+'&teachingGroupName='+s+'&manageId=${user.teacherid}',
      async : false,
      dataType : 'json',
      success : function(data) {
        infor_data1 = data.data
        total1 = data.total
      },
      error : function() {
        alert('error');
      }
    });
    var rows1 = [];
    if(infor_data1!=null) {
      for (var i1 = 0; i1 < infor_data1.length; i1++) {
        rows1.push({
          total: total1,
          wh: s,
          teachingGroupId: infor_data1[i1].teachingGroupId,
          teachingGroupMame: infor_data1[i1].teachingGroupMame,
          teachingGroupManageId: infor_data1[i1].teachingGroupManageId
        });
      }
    }
    return rows1;
  }
  function pagerFilter1(data){
    if(i==1&&data[0]!=null){
      var to = data[0].total;
      var wh = data[0].wh;
    }else if(i==2&&data!=null){
      var to = data.total;
      var wh = data.wh;
    }else{
      var to = 0;
      var wh = "";
    }
    if (typeof to== 'number' && typeof data.splice == 'function'){	// is array
      data = {
        total:to,
        rows: data,
        wh:wh
      }
      i=2;
    }
    var dg = $(this);
    var opts = dg.datagrid('options');
    var pager = dg.datagrid('getPager');
    pager.pagination({
      onSelectPage:function(pageNum, pageSize){
        opts.pageNumber = pageNum;
        opts.pageSize = pageSize;
        pager.pagination('refresh',{
          pageNumber:pageNum,
          pageSize:pageSize
        });
        var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
//    var end = start + parseInt(opts.pageSize);
        data.rows = (getData1(start,parseInt(opts.pageSize),wh));
        dg.datagrid('loadData',data);
      }
    });
    return data;
  }

  function submitForm1() {
    $('#ff2').form('submit', {
      url : 'rest/page/manageTeaGroup/add',
      onSubmit: function () {
        return $(this).form('enableValidation').form('validate');
      },
      success : function(data){
        var obj = JSON.parse(data)
        if(obj.code == 200){
          $.messager.show({title:'操作提示',msg:obj.message,showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
          $('#test2').window('close');
        }else{
          $.messager.show({title:'操作提示',msg:obj.message,showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }
      }
    });
  }

  function clearForm() {
    $('#ff2').form('clear');
  }
</script>
</body>
</html>
